package com.huifer.wgx.controller;

import com.huifer.wgx.model.ResultPointAttrEntity;
import com.huifer.wgx.model.WorkEntity;
import com.huifer.wgx.pojo.CommonResult;
import com.huifer.wgx.service.ResultPointAttrService;
import com.huifer.wgx.service.RtkService;
import com.huifer.wgx.utlis.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>Title : ResultPointAttrController </p>
 * <p>Description : 成果点额外属性</p>
 *
 * @author huifer
 * @date 2019-03-15
 */
@RestController
@RequestMapping("result_point_attr")
@Api(tags = "ResultPointAttrController", description = "成果点额外属性管理")
public class ResultPointAttrController {

    @Autowired
    private ResultPointAttrService pointAttrService;
    private CommonResult commonResult = new CommonResult();

    @ApiOperation("创建额外点属性")
    @PostMapping("/save")
    public ResponseEntity saveResultPointAttrEntity(
            ResultPointAttrEntity resultPointAttrEntity) {
        try {
            ResultPointAttrEntity save = pointAttrService.save(resultPointAttrEntity);
            return ResponseEntity.ok(commonResult.success(save));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }


    @ApiOperation("查询所有成果点额外属性")
    @GetMapping("/find_all")
    public ResponseEntity findAll(
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult.success(pointAttrService.findAll(pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }
}
